package com.dmcb.trade.business.utils;

import com.dmcb.common.business.utils.JsonUtil;
import com.dmcb.common.business.utils.WebUtil;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * uc头条
 * Created by miting on 2018/12/25
 */
public class UCTouTiaoCrawlUtil {

    public static Map<String, String> getInfo(String link) {
        Map<String, String> map = new HashMap<>();
        Map<String, Object> map1;//http://a.mp.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt&wm_aid=4ea900f6693543599b68b711a22cd766
        String id = link.substring(link.lastIndexOf("_aid=")+5);
        String json = WebUtil.buildRequest("http://ff.dayu.com/contents/origin/"+id+"?biz_id=1002&_fetch_author=1&_fetch_incrs=1", false);
        map1 = JsonUtil.getResult(json);
        if (map1 == null || map1.size() == 0) {
            return null;
        }
        map1 = (Map) map1.get("data");
        String title = (String) map1.get("title");
        if (StringUtils.isBlank(title)) {
            return null;
        }
        map.put("title", title);
        return map;
    }

}
